//main.vue文件
<template>
  <view class="content">
    <tn-tips ref="tips" position="top"></tn-tips>
    <tn-toast ref="toast"></tn-toast>
    <view class="title">
      <tn-button style="margin-right: 20rpx;" @click="click" backgroundColor="#01BEFF" fontColor="#080808">点击扫码</tn-button>
      <tn-button @click="click2" backgroundColor="#01BEFF" fontColor="#080808">扫码内容</tn-button>
    </view>
    <my-tabbar :currentTab='0' />
  </view>
</template>

<script>
  export default {
    data() {
      return {
        d: '6'
      }
    },
    onLoad() {},
    methods: {
      click() {
        // 只允许通过相机扫码
        uni.scanCode({
          // onlyFromCamera: true,
          success: (res) => {
            console.log('条码类型：' + res.scanType);
            console.log('条码内容：' + res.result);
            this.d = res.result;
            this.$refs.toast.show({
              title: '核销成功',
              content: '订单号:' + this.d,
              icon: 'success',
              image: '',
              duration: 1500
            })
          }
        });
      },
      click2() {
        this.$refs.tips.show({
          msg: this.d,
          backgroundColor: '#E83A30',
          fontColor: '#FFFFFF',
          duration: 1500
        })
      }
    }
  }
</script>

<style lang="scss">
.title{
  display: flex;
  justify-content: center;
}
</style>